package com.springdoor.web.controller.goods;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.springdoor.common.annotation.Log;
import com.springdoor.common.core.controller.BaseController;
import com.springdoor.common.core.domain.AjaxResult;
import com.springdoor.common.enums.BusinessType;
import com.springdoor.goods.domain.SprdCommonImages;
import com.springdoor.goods.service.ISprdCommonImagesService;
import com.springdoor.common.utils.poi.ExcelUtil;
import com.springdoor.common.core.page.TableDataInfo;

/**
 * 图片资源Controller
 * 
 * @author ruoyi
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/goods/images")
public class SprdCommonImagesController extends BaseController
{
    @Autowired
    private ISprdCommonImagesService commonImagesService;

    /**
     * 查询图片资源列表
     */
    @PreAuthorize("@ss.hasPermi('goods:images:list')")
    @GetMapping("/list")
    public TableDataInfo list(SprdCommonImages commonImages)
    {
        startPage();
        List<SprdCommonImages> list = commonImagesService.selectSprdCommonImagesList(commonImages);
        return getDataTable(list);
    }

    /**
     * 导出图片资源列表
     */
    @PreAuthorize("@ss.hasPermi('goods:images:export')")
    @Log(title = "图片资源->导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SprdCommonImages commonImages)
    {
        List<SprdCommonImages> list = commonImagesService.selectSprdCommonImagesList(commonImages);
        ExcelUtil<SprdCommonImages> util = new ExcelUtil<SprdCommonImages>(SprdCommonImages.class);
        util.exportExcel(response, list, "图片资源数据");
    }

    /**
     * 获取图片资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:images:query')")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(commonImagesService.selectSprdCommonImagesByImageId(imageId));
    }

    /**
     * 新增图片资源
     */
    @PreAuthorize("@ss.hasPermi('goods:images:add')")
    @Log(title = "图片资源->新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SprdCommonImages commonImages)
    {
        commonImages.setCreateBy(getUsername());
        commonImages.setUpdateBy(getUsername());
        return toAjax(commonImagesService.insertSprdCommonImages(commonImages));
    }

    /**
     * 修改图片资源
     */
    @PreAuthorize("@ss.hasPermi('goods:images:edit')")
    @Log(title = "图片资源->修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SprdCommonImages commonImages)
    {
        commonImages.setUpdateBy(getUsername());
        return toAjax(commonImagesService.updateSprdCommonImages(commonImages));
    }

    /**
     * 删除图片资源
     */
    @PreAuthorize("@ss.hasPermi('goods:images:remove')")
    @Log(title = "图片资源->删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(commonImagesService.deleteSprdCommonImagesByImageIds(imageIds));
    }


    /**
     * 获取未选中的图片
     */
    @PreAuthorize("@ss.hasPermi('goods:images:query')")
    @GetMapping("/findNoSelImagesList")
    public TableDataInfo findNoSelImagesList(SprdCommonImages commonImages) {
        startPage();
        List<SprdCommonImages> list = commonImagesService.findNoSelImagesList(commonImages);
        return getDataTable(list);
    }
}
